package com.itheima.test2;

import java.net.*;

/**
 * @Author:gy
 * @Date: 2025/09/04 9:09
 * @Description:
 */
public class ServeDemo {
    public static void main(String[] args) throws Exception {
        //单播的码头
       // DatagramSocket ds = new DatagramSocket(10010);
        //主播的码头
        MulticastSocket ms = new MulticastSocket(10010);
        DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);
        //把我们的计算机绑定一个组播小组,加入这个小组.
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));
        ms.receive(dp);
        //解析礼物
        byte[] data = dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data, 0, length));
        //关闭主播码头
        ms.close();
    }
}
